#include <func.h>

int main()
{
    char buff1[6] = {0};
    char buff2[6] = {0};

    int fd = open("file2.txt", O_RDWR);
    ERROR_CHECK(fd, -1, "open");

    //先定义一个多个缓冲区的iov数组
    struct iovec iov[2];
    iov[0].iov_base = buff1;
    iov[0].iov_len = sizeof(buff1);
    iov[1].iov_base = buff2;
    iov[1].iov_len = sizeof(buff2);

    //分散读, 调用一次readv函数，就可以将文件中的数据放入
    //两片缓冲区中，不需要调用两次read函数
    int ret = readv(fd, iov, 2);
    printf("ret: %d\n", ret);
    printf("buff1: %s\n", buff1);
    printf("buff2: %s\n", buff2);

    close(fd);
    return 0;
}

